package com;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class ReadFile {
	public static void main(String[] args) throws IOException {
		File f = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg");
		File fs = new File("e:\\aaa\\企鹅.jpg");
		/*
		 * BufferedReader bd=new BufferedReader(new InputStreamReader(new
		 * FileInputStream(f),"utf-8")); BufferedWriter bw=new
		 * BufferedWriter(new OutputStreamWriter(new
		 * FileOutputStream(fs),"utf-8"));
		 * 
		 * String s=bd.readLine(); while(s!=null){ bw.write(s); s=bd.readLine();
		 * } bw.flush(); bd.close();bw.close();
		 */
		if(!f.exists()){
			throw new IllegalArgumentException("文件不存在");
		}
		if(!f.isFile()){
			throw new IllegalArgumentException("不是文件");
		}
		
		FileInputStream in=new FileInputStream(f);
		FileOutputStream out=new FileOutputStream(fs);
		
		byte[] buf = new byte[1024*8];
		int b;
        while((b=in.read(buf,0,buf.length))!=-1){
        	out.write(buf, 0, b);
        	out.flush();//最好加上
        }
        in.close();
        out.close();
	}
}
